﻿using System;
using System.Collections.Generic;
using System.Text;

namespace AttributeDemo
{
    public class InvokeCenter
    {
        public static void ManagerPeople<T>(ChinesePeople people) where T : class
        {
            people.Speak();
            Type type = people.GetType();
            if (type.IsDefined(typeof(ZiDingYiAttribute),false))
            {
                object[] attributes = type.GetCustomAttributes(typeof(ZiDingYiAttribute), true);
                foreach (ZiDingYiAttribute attribute in attributes)
                {
                    attribute.Show();
                }

                foreach (var  prop in type.GetProperties())
                {
                    if (prop.IsDefined(typeof(ZiDingYiAttribute), true))
                    {
                        object[] propAttributes = prop.GetCustomAttributes(typeof(ZiDingYiAttribute), true);
                        foreach (ZiDingYiAttribute attribute in propAttributes)
                        {
                            attribute.Show();
                        }
                    }
                }

                foreach (var method in type.GetMethods())
                {
                    if (method.IsDefined(typeof(ZiDingYiAttribute), true))
                    {
                        object[] methodAttributes = method.GetCustomAttributes(typeof(ZiDingYiAttribute), true);
                        foreach (ZiDingYiAttribute attribute in methodAttributes)
                        {
                            attribute.Show();
                        }
                    }
                }
            }
        }
    }
}
